﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.ErrorCode;
using Traceability.Read.Api.Application.Command.CommodityCommand;
using Traceability.Read.Api.Dto;

namespace Traceability.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CommodityController : ControllerBase
    {

        private readonly IMediator mediator;

        public CommodityController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 显示商品信息操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<List<CommodityDto>>> GetCommodity([FromQuery] GetCommodityCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 查询商品名称处理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<CommodityNameDto>>> GetCommodityName([FromQuery] GetCommodityNameCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// id查询商品操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<CommodityDto>>> Handle([FromQuery] GetCommodityIdCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
